<style lang="scss" scoped>
.user{
	image{
		border-radius: 50%;
		width: 150rpx;
	}
	text{
		line-height: 150rpx;
	}
}
.plate image{
	width: 180rpx;
}
textarea{
	box-sizing: border-box;
}
.getUserInfo{
	width: 100vw;
	height: 100vh;
	background: #fff;
	position: absolute;
	top: 0;left: 0;
	z-index: 1;
	padding-top: calc(50vh - 55rpx);
	.button{
		width: 300rpx;
	}
}
.container{
	background-color: $uni-bg-color-grey;
	min-height: calc(100vh - 12px);
}
.feedback{
	.title{
		font-size: 42rpx;
		color:$uni-color-primary;
		display: block;
		font-weight: bold;
	}
	.sub-title{
		font-size: 26rpx;
		color: #999;
	}
}
</style>
<template>
	<view class="container py-3">
		<view v-if="authorize">
			<view class="user auto-90 d-flex bg-fff border-radius px-2 py-4">
				<image :src="avatarUrl" mode="widthFix" class="mr-4"/>
				<text>{{nickName}}</text>
			</view>
			<view class="d-flex px-2 py-4 auto-90 around my-5 bg-fff border-radius">
				<navigator url="./list?type=1" class="plate text-center" >
					<image src="https://gov-tool.js-cx.cn/static/home/img/collect.png" mode="widthFix" class="d-block box-shadow border-radius"/>
					<text class="mt-2 font-30 color-999">我的收藏</text>
				</navigator>
				<view class="plate text-center" @click="goQuestionnaire">
					<image src="https://gov-tool.js-cx.cn/static/home/img/appeal.png" mode="widthFix" class="d-block box-shadow border-radius"/>
					<text class="mt-2 font-30 color-999">我的问卷</text>
				</view>
				<navigator url="./list?type=0" class="plate text-center" >
					<image src="https://gov-tool.js-cx.cn/static/home/img/history.png" mode="widthFix" class="d-block box-shadow border-radius"/>
					<text class="mt-2 font-30 color-999">我的足迹</text>
				</navigator>
			</view>
			<view class="border-radius auto-90 bg-fff px-3 py-5 clearfix feedback">
				<!-- <image src="/static/img/feedback.png"  mode="widthFix" style="width:150rpx"></image> -->
				<text class="title">意见反馈</text>
				<text class="sub-title">留下您的宝贵意见,帮助我们做的更好！</text>
				<textarea :maxlength="140" class="border p-1 border-radius w-100b mt-2" v-model="msg"/>
				<button type="primary" class="float-right mt-2 primary-btn" size="mini" @click="submit">提交</button>
			</view>
		</view>
		<view class="getUserInfo" v-else>
			<button type="primary" class="button" open-type="getUserInfo" @click="getUserInfo">授权登录</button>
		</view>
	</view>
</template>

<script>
	import {msgBoard} from "@api"
	import WXBizDataCrypt from "../../static/api/WXBizDataCrypt.js"
	export default {
		data() {
			return {
				msg:'',
				nickName:"",
				avatarUrl:'',
				authorize:true,
			}
		},
		methods:{
			goQuestionnaire(){
				uni.navigateToMiniProgram({
					appId:"wxebadf544ddae62cb",
					path:"pages/survey/index?sid=9335470&hash=89a1",
				})
			},
			submit(){
				msgBoard({msg:this.msg,openid:uni.getStorageSync('openid'),nickName:uni.getStorageSync('nickName'),})
				.then(res=>{
					this.msg=''
					uni.showToast({
					    title: '反馈成功',
					});
				})
			},
			getUserInfo(){
				uni.getUserProfile({
					desc:'Wexin',
					success: res => {
						//解密encryptedData，可获取用户openId
						uni.setStorageSync("nickName",res.userInfo.nickName)
						uni.setStorageSync("avatarUrl",res.userInfo.avatarUrl)
						this.nickName=res.userInfo.nickName
						this.avatarUrl=res.userInfo.avatarUrl
						this.authorize=true
					
					},
					fail: err => {
						console.log('获取用户信息错误：', err)
					}
				})
			}
		},
		onLoad() {
			this.authorize=!!uni.getStorageSync("avatarUrl")
			if(uni.getStorageSync("avatarUrl")){
				this.authorize=true
				this.avatarUrl=uni.getStorageSync("avatarUrl")
				this.nickName=uni.getStorageSync("nickName")
			}
				
		}
	}
</script>
